package cn.cnsuh.剑指offer.q42_连续子数组的最大和;

public class Main {
    public static void main(String[] args) {
        int[] arr = {-2,1,-3,4,-1,2,1,-5,4};
        System.out.println("maxSubArray(arr) = " + maxSubArray(arr));
    }
    static int maxSubArray(int[] nums) {
        int res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            nums[i] += Math.max(nums[i-1],0);
            res = Math.max(nums[i],res);
        }
        return res;
    }
}
